home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 446_01 / DOC / DPSTART / TEST2 / MAKEFILE < prev    next >
Encoding:
Text File  |  1996-04-18  |  9.9 KB  |  309 lines

  1. # Makefile-name: Makefile.app
  2. #############################################################################
  3. #                                                                           #
  4. # (c) Copyright 1994 by                                                     #
  5. #     SINTEF, Oslo, Norway.                                                 #
  6. #     All rights reserved.                                                  #
  7. #                                                                           #
  8. #     See the file Copyright.h for further details.                         #
  9. #                                                                           #
  10. #############################################################################
  11.  
  12. # $Id: Makefile.app,v 1.5 1995/03/23 11:40:11 tvs Exp $
  13. #
  14. # authors: Hans Petter Langtangen and Trond Vidar Stensby, SINTEF/UiO
  15. #
  16.  
  17. # This Makefile is intended for application programs using libraries.
  18. # There can only be one main program in each directory since this Makefile
  19. # compiles and links all .C .c and .f files in the current directory.
  20. # If several main programs are desireable, use the file
  21. # Makefile.app_1f.
  22.  
  23. # **** You will seldom have to modify this file ****
  24.  
  25. # All variables in this Makefile have default values that may be ok.
  26. # It is recommended not to edit this makefile. Instead the problem
  27. # dependent variables should be assigned in the user files .pdmkroot
  28. # (PROJECTROOT and PACKAGES) and .pdmkvars (DIRS, SRCS, etc.).
  29. # Both these files are included if they exist.
  30. #
  31. # A safe way of using the Makefiles is to let the script Mkdir
  32. # copy and customize the files.
  33. #
  34. # The items to be modified are usually the variables 
  35. # LIBS, INCLUDEDIRS, SRCDIR, APPL, PACKAGES and PROJECTROOT. 
  36. # LIBS contains the libraries with which the application is to be linked.
  37. # INCLUDEDIRS contains the directories that will be searched for
  38. # include files.
  39. # SRCDIR contains the path to the directory $(PROJECTROOT)/src. 
  40. # If the directory containing this Makefile is a part of the $(PROJECTROOT) 
  41. # tree, a relative path should appear in PROJECTROOT.
  42. # APPL is the name of the executable file after compiling and linking.
  43. # You may also want to include another header file for predefined
  44. # variables.
  45. #
  46. # The executable file is called app, by default. 
  47. # You may prescribe app with another name by assigning the value APPL in
  48. # .pdmkvars
  49.  
  50. # -----------------------------------------------------------------------
  51.  
  52. # The MakeFlags files supports two set of makefiles:
  53. MakeFileVersion := NewStyle
  54.  
  55. # root of present project:
  56. PROJECTROOT := ../../..
  57.  
  58. # default is no PACKAGES
  59. PACKAGES := 
  60. TESTPACK :=
  61. INSTPACK :=
  62.  
  63. # redefine PROJECTROOT and PACKAGES ?
  64.  
  65. ifeq "$(wildcard .pdmkroot)" ".pdmkroot"
  66.    include .pdmkroot
  67. endif
  68.  
  69. # ----------- default values ------------
  70.  
  71. # predefined gnumake variables: 
  72.  
  73. include $(wildcard $(PROJECTROOT)/src/MakeHeader)
  74.  
  75. # Get definition of compiler flags from all packages.
  76. # The MakeFlags files from the different packages should be included
  77. # in the opposite order than listed in the variable $(PACKAGES)
  78.  
  79. ifneq "$(PACKAGES)" ""
  80.    REVERSE := $(shell reverse_args $(PACKAGES) )
  81.    include $(foreach dir,$(REVERSE),$(wildcard $(dir)/src/MakeFlags))
  82. endif
  83.  
  84. # include this package MakeFlags.
  85. include $(wildcard $(PROJECTROOT)/src/MakeFlags)
  86.  
  87. # directories containing the files to be compiled (can be overrided):
  88.  
  89. DIRS :=
  90.  
  91. # the name of the executable file after compiling and linking.
  92. APPL := app
  93.  
  94. # the source files are all the .C, .c and .f files in current directory
  95. # and the files in the directories in DIRS:
  96. SRCS := $(wildcard ./*.[Ccf])
  97.  
  98. # all *.C files make up the library (sometimes the user overrides the SRCS
  99. # variable - e.g. for compiling a single file - and then ALLSRCS indicates
  100. # the files that should enter the library):
  101.  
  102. ALLSRCS := $(wildcard ./*.[Ccf])
  103.  
  104. # the tilde files (to be removed by clean):
  105. TILD := $(wildcard ./*~)
  106.  
  107. # ----------- redefine problem dependent variables ------------
  108.  
  109. ifeq "$(wildcard .pdmkvars)" ".pdmkvars"
  110.    include $(wildcard .pdmkvars)
  111. endif
  112.  
  113. #------------ the below statements should not be modified ----------------
  114.  
  115. # the source files are all the .C, .c and .f files in current directory
  116. # and the files in the directories in DIRS:
  117. SRCS := $(SRCS) $(foreach dir,$(DIRS),$(wildcard $(dir)/*.[Ccf]))
  118.  
  119. # all *.C files make up the library (sometimes the user overrides the SRCS
  120. # variable - e.g. for compiling a single file - and then ALLSRCS indicates
  121. # the files that should enter the library):
  122.  
  123. ALLSRCS := $(ALLSRCS) $(foreach dir,$(DIRS),$(wildcard $(dir)/*.[Ccf]))
  124.  
  125. # the tilde files (to be removed by clean):
  126. TILD := $(TILD) $(foreach dir,$(DIRS),$(wildcard $(dir)/*~))
  127.  
  128. # remove multiple entries
  129.  
  130. SRCS    := $(sort $(SRCS))
  131. ALLSRCS := $(sort $(ALLSRCS))
  132. TILD    := $(sort $(TILD))
  133.  
  134. ifeq ($(LINKLEVEL),install)
  135.   PACKDIR := $(shell add_suffix "$(PACKAGES)" "/src" "$(TESTPACK)")
  136. else
  137.   TP := $(shell remove_elem "$(PACKAGES)" "$(INSTPACK)")
  138.   ifneq "$(TP)" ""
  139.     PACKDIR :=$(shell add_suffix "$(PACKAGES)" "/src" "$(TP)")
  140.   else
  141.     PACKDIR := $(PACKAGES)
  142.   endif
  143. endif
  144.  
  145. ifeq ($(LINKLEVEL),install)
  146. INCLUDEDIRS := $(foreach dir,$(DIRS),-I$(dir)) \
  147.                $(INCLUDEDIRS) -I$(PROJECTROOT)/include \
  148.                $(foreach pack,$(PACKDIR),-I$(pack)/include)
  149.  
  150. else
  151. INCLUDEDIRS := $(foreach dir,$(DIRS),-I$(dir)) \
  152.                $(INCLUDEDIRS) -I$(PROJECTROOT)/src/include \
  153.                $(foreach pack,$(PACKDIR),-I$(pack)/include)
  154. endif
  155.  
  156. # file for results from verification procedures (test problems):
  157. VERIFYLOG := $(PWD)/verify.log
  158.  
  159.  
  160. #-----------------------------------------------------------------------
  161. # the application is dependent on libraries in the following directories:
  162. #-----------------------------------------------------------------------
  163.  
  164. # LDPATH contains the directories where ld search for libraries, these
  165. # directories depend on the LINKLEVEL variable (value equal to install or 
  166. # test). LINKLEVEL=test means that programs are linked to libraries in the
  167. # test version, while LINKLEVEL=install means that one links to installed
  168. # libraries.
  169.  
  170. ifeq ($(LINKLEVEL),install)
  171. # VPATH should contain the same directories as LDPATH
  172. # if there are error messages like "No way to make -ltop", VPATH may
  173. # be wrong. It may help putting all parts of LDPATH on the same line,
  174. # or use := assignment and no \ extension of lines!
  175.  
  176. LDPATH  :=  $(LDPATH) -L$(PROJECTROOT)/lib/$(LIBTYPE)/$(EXT)\
  177. $(foreach pack,$(PACKDIR),-L$(pack)/lib/$(LIBTYPE)/$(EXT))
  178.  
  179. else # test version of libraries (search in /src - directories first):
  180.  
  181. LDPATH  := $(LDPATH) -L$(PROJECTROOT)/src/lib/$(LIBTYPE)/$(EXT)\
  182. $(foreach pack,$(PACKDIR), -L$(pack)/lib/$(LIBTYPE)/$(EXT))
  183. endif
  184.  
  185. # VPATH should contain the same directories as LDPATH
  186. VPATH := $(patsubst -L%,:%,$(LDPATH))
  187. VPATH := $(patsubst -I%,:%,$(VPATH))
  188. VPATH := $(subst $(empty) :,:,$(strip $(VPATH)))
  189.  
  190. # Only normal (*.a) libraries kan be a part of the dependencies
  191. ifneq ($(SHARED),on)
  192.    DEPLIBS := $(LIBS) $(SYSLIBS)
  193. else
  194.    DEPLIBS :=
  195. endif
  196.  
  197. # let the object files be the *.[Ccf] files but with .[Ccf] replaced by .o:
  198.  
  199. OBJS := $(SRCS:.C=.o)
  200. OBJS := $(OBJS:.c=.o)
  201. OBJS := $(OBJS:.f=.o)
  202.  
  203. OBJS := $(foreach obj,$(OBJS),$(PREFIX)$(obj))
  204.  
  205. # ALLOBJS is used when linking, ALLSRCS is used to make ALLOBJS
  206. ALLOBJS := $(subst .C,.o,$(ALLSRCS)) 
  207. ALLOBJS := $(subst .c,.o,$(ALLOBJS))
  208. ALLOBJS := $(subst .f,.o,$(ALLOBJS))
  209.  
  210. ALLOBJS := $(foreach obj,$(ALLOBJS),$(PREFIX)$(obj))
  211.  
  212. # dependencies for make depend should be equal to all object files, but
  213. # with .o suffix replaced with .d
  214.  
  215. DEPFILES    := $(OBJS:.o=.d)
  216.  
  217. # Make dependencies invisible
  218.  
  219. ifeq ("$(OUTPUT)","INVISIBLE")
  220.    DEPFILES := $(foreach file,$(DEPFILES),$(dir $(file)).$(notdir $(file)))
  221. endif
  222.  
  223. # preprocessor files should be equal to all object files, but
  224. # with .o suffix replaced with .E
  225.  
  226. PREPROFILES := $(OBJS:.o=.E)
  227.  
  228. # Check that *.o files are of the right type
  229. $(shell newcomptype "$(PREFIX)" "$(LIBTYPE)" \
  230.   "$(CXXFLAGS) $(CCFLAGS) $(FFLAGS) $(LDFLAGS)" "$(OBJS)")
  231.  
  232. include $(wildcard $(PROJECTROOT)/src/MakeRules)
  233.  
  234. # Rules for making the application, and rules for clean. depend, ...
  235. #-----------------------------------------------------------------------------
  236.  
  237. all:    $(APPL)
  238.     @echo
  239.     @echo "---------- application \"$(APPL)\" done ----------"
  240.  
  241.  
  242. $(APPL): $(OBJS) $(DEPLIBS)
  243.     @echo
  244.     @echo
  245.     @echo "---------- linking $(OBJS) ----------"
  246.     @echo
  247.     @echo
  248.     $(LD) $(LDFLAGS) -o $@ $(ALLOBJS) $(LIBS) $(SYSLIBS)
  249.         ifeq ("$(INSTALL_EXE)","yes")
  250.         @mkdirhier $(PROJECTROOT)/bin/$(LIBTYPE)/$(EXT)
  251.         @mv $@ tmp
  252.         @mv tmp $(PROJECTROOT)/bin/$(LIBTYPE)/$(EXT)/$@
  253.         @echo "\n`ls -l $(PROJECTROOT)/bin/$(LIBTYPE)/$(EXT)/$@ | \
  254.         awk '{print $$5, $$6, $$7, $$8, $$9}'`" ;
  255.         endif
  256.  
  257. clean:
  258.     @echo removing `ls -s $(OBJS) $(TILD) $(APPL) $(PREPROFILES) core *.bak SIMULATION.* .SIMULATION* 2> /dev/null`
  259.     @rm -f $(OBJS) $(TILD) $(APPL) $(PREPROFILES) core *.bak SIMULATION.* .SIMULATION*
  260.  
  261. cleanex:
  262.     rm -f $(TILD) $(APPL) core *.bak
  263.     rm -f $(PROJECTROOT)/bin/$(LIBTYPE)/$(EXT)/$(APPL)
  264.  
  265. clobber:
  266.     @echo removing `ls -s $(ALLOBJS) $(DEPFILES) $(TILD) $(APPL) core *.bak SIMULATION.* .SIMULATION* .comptype 2> /dev/null`
  267.     @rm -f $(OBJS) $(DEPFILES) $(TILD) $(APPL) core *.bak SIMULATION.* .SIMULATION* .comptype
  268.  
  269. depend: $(DEPFILES)
  270.     @echo
  271.     @echo "---------- Dependencies done ----------"
  272.  
  273. headercp:
  274.     @echo
  275.     @echo "---------- No headercp in application dir ----------"
  276.  
  277. newverify:
  278.     @echo
  279.     @echo "In directory `pwd`"
  280.     @echo Results from last verification registered as reference.
  281.     @NewVerify
  282.  
  283. prepro: $(PREPROFILES)
  284.     @echo
  285.     @echo "---------- Preprocessing done ----------"
  286.  
  287. removelib:
  288.     @echo
  289.     @echo "---------- No removelib in application dir ----------"
  290.  
  291. verifyall: all verify clean
  292.  
  293. verify:
  294.     @echo
  295.     @echo "Using input in `pwd`"
  296.     @echo "(Results in $(VERIFYLOG))"
  297.         ifeq ($(MAKELEVEL),0)
  298.     @rm -f verify.log ; touch verify.log
  299.         endif
  300.     @echo "Verifications run on $$HOSTTYPE\n\n\n" >> $(VERIFYLOG)
  301.     @Verify $(VERIFYLOG)
  302.  
  303. # Include dependencies.
  304.  
  305. ifneq "$(foreach file,$(DEPFILES),$(wildcard $(file)))" ""
  306.    include $(foreach file,$(DEPFILES),$(wildcard $(file)))
  307. endif
  308.